#include<bits/stdc++.h>
using namespace std;
int T,n,a[2010],dp[2010][2010],val[2010][2010];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>T;
    while(T--)
    {
    memset(val,0,sizeof(val));
    memset(dp,0,sizeof(dp));
    int ans=0;
    cin>>n;
    if(n>2000)break;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<=i-1;j++)
        {
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+(a[i]==a[i+1]?a[i+1]:0));
            dp[i+1][i]=max(dp[i+1][i],dp[i][j]+(a[i+1]==a[j]?a[i+1]:0));
        }
    }
    for(int i=0;i<=n;i++)
          ans=max(ans,dp[n][i]);
    cout<<ans<<'\n';
    }
    return 0;
}
